package com.findFish.water.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.findFish.common.annotation.Log;
import com.findFish.common.core.controller.BaseController;
import com.findFish.common.core.domain.AjaxResult;
import com.findFish.common.enums.BusinessType;
import com.findFish.water.domain.EnvironmentAlerts;
import com.findFish.water.service.IEnvironmentAlertsService;
import com.findFish.common.utils.poi.ExcelUtil;
import com.findFish.common.core.page.TableDataInfo;

/**
 * 环境异常报警Controller
 * 
 * @author admin
 * @date 2025-04-01
 */
@RestController
@RequestMapping("/water/alerts")
public class EnvironmentAlertsController extends BaseController
{
    @Autowired
    private IEnvironmentAlertsService environmentAlertsService;

    /**
     * 查询环境异常报警列表
     */
    @PreAuthorize("@ss.hasPermi('water:alerts:list')")
    @GetMapping("/list")
    public TableDataInfo list(EnvironmentAlerts environmentAlerts)
    {
        startPage();
        List<EnvironmentAlerts> list = environmentAlertsService.selectEnvironmentAlertsList(environmentAlerts);
        return getDataTable(list);
    }

    /**
     * 导出环境异常报警列表
     */
    @PreAuthorize("@ss.hasPermi('water:alerts:export')")
    @Log(title = "环境异常报警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EnvironmentAlerts environmentAlerts)
    {
        List<EnvironmentAlerts> list = environmentAlertsService.selectEnvironmentAlertsList(environmentAlerts);
        ExcelUtil<EnvironmentAlerts> util = new ExcelUtil<EnvironmentAlerts>(EnvironmentAlerts.class);
        util.exportExcel(response, list, "环境异常报警数据");
    }

    /**
     * 获取环境异常报警详细信息
     */
    @PreAuthorize("@ss.hasPermi('water:alerts:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(environmentAlertsService.selectEnvironmentAlertsById(id));
    }

    /**
     * 新增环境异常报警
     */
    @PreAuthorize("@ss.hasPermi('water:alerts:add')")
    @Log(title = "环境异常报警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EnvironmentAlerts environmentAlerts)
    {
        return toAjax(environmentAlertsService.insertEnvironmentAlerts(environmentAlerts));
    }

    /**
     * 修改环境异常报警
     */
    @PreAuthorize("@ss.hasPermi('water:alerts:edit')")
    @Log(title = "环境异常报警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EnvironmentAlerts environmentAlerts)
    {
        return toAjax(environmentAlertsService.updateEnvironmentAlerts(environmentAlerts));
    }

    /**
     * 删除环境异常报警
     */
    @PreAuthorize("@ss.hasPermi('water:alerts:remove')")
    @Log(title = "环境异常报警", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(environmentAlertsService.deleteEnvironmentAlertsByIds(ids));
    }
}
